{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/Users/pengxiao/Documents/tmp/test1/4.text\n",
      "/Users/pengxiao/Documents/tmp/test1/test2/5.txt\n",
      "/Users/pengxiao/Documents/tmp/test1/3.text\n",
      "/Users/pengxiao/Documents/tmp/2.txt\n",
      "/Users/pengxiao/Documents/tmp/1.txt\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "path = '/Users/pengxiao/Documents/tmp'\n",
    "\n",
    "def get_file(folder_name):\n",
    "    for item in os.listdir(folder_name):\n",
    "        full_path = os.path.join(folder_name, item)\n",
    "        if os.path.isfile(full_path):\n",
    "            yield full_path\n",
    "        elif os.path.isdir(full_path):\n",
    "            # ???????\n",
    "            # for item in get_file(full_path):\n",
    "            #    yield item\n",
    "            yield from get_file(full_path)\n",
    "\n",
    "for file_name in get_file(path):\n",
    "    print(file_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
